using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ClassifierLib.Classifier.Filters
{
    /// <summary>
    /// This class implements the base selection method
    /// </summary>
    public class SelectFilter : RuleFilter
    {
     
        private Action _desiredAction;

        public SelectFilter()
        {
            if (!RegisteredTypes.Contains(GetType()))
                RegisteredTypes.Add(GetType()); 
        }
        public override Population Apply(Population Population, Population MatchSet, Environment.State State, Action Action)
        {
            CalculateStatistics(Population, MatchSet);

            SelectionMethod(MatchSet);

            return FindActionSetRules(MatchSet);
        }

        /// <summary>
        /// Method that does selection based on statistics
        /// </summary>
        public virtual void SelectionMethod(Population MatchSet)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Searches match rules for all with selected  action
        /// </summary>
        /// <param name="PopSet"></param>
        /// <returns></returns>
        private Population FindActionSetRules(Population MatchSet)
        {
            Population result = new Population();
            
            foreach (Rule r in MatchSet)
            {
                //If wanting to use Roulette wheel use this code, but not in XCS!
                //if (r.Action.Equals(c))
                //    result.Add(r);
                
                if (r.Action.Equals(DesiredAction))
                    result.Add(r);
            }
            return result;
        }

        /// <summary>
        /// This function generates statistical information on the selected population
        /// </summary>
        /// <param name="population"></param>
        /// <param name="selected"></param>
        public virtual void CalculateStatistics(Population Population, Population Selected)
        {
            throw new NotImplementedException();
        }

        protected Action DesiredAction
        {
            get
            {
                return _desiredAction;
            }
            set
            {
                _desiredAction = value;
            }
        }
    }
}
